
const buttonMethods = {
    clickBtn(e) {//根据点击类型的不同分流到指定函数
        this[e]();
    },
    // 渲染本地数据
    renderLocal() {
        if (this.json.nodes.length == 0) {
            this.renderDefaultLineage()
        } else {
            this.clear()
        }
    },
    //清空画布
    clear() {
        if (Object.keys(this.json.nodes).length) {
            this.jsplumbInstance.deleteEveryConnection();
            this.jsplumbInstance.deleteEveryEndpoint();
            this.json.nodes.forEach((node) => {
                this.jsplumbInstance.remove(node.name);
            });
        }
        this.json = {
            nodes: [],
            edges: []
        }
    },
    //刷新
    refresh() {
        this.loading = true
        this.scale = 1
        this.clear()
        setTimeout(() => {
            if (this.json.nodes.length == 0) {
                this.renderDefaultLineage()
                this.$message.success("刷新成功!");
            } else {
                this.clear()
                this.$message.console.error("刷新失败!");
            }
            this.loading = false
        }, 500)
    },
    //放大
    enlargeClick() {
        if (this.scale > 1.3) return
        this.scale += 0.1
    },
    //缩小
    reduceClick() {
        if (this.scale < 0.6) return
        this.scale -= 0.1
    },
    //返回
    goback() {
        this.refresh()
    },
    //全屏
    screen() {
        let element = document.documentElement;
        if (this.fullscreen) {
            if (document.exitFullscreen) {
                document.exitFullscreen();
            } else if (document.webkitCancelFullScreen) {
                document.webkitCancelFullScreen();
            } else if (document.mozCancelFullScreen) {
                document.mozCancelFullScreen();
            } else if (document.msExitFullscreen) {
                document.msExitFullscreen();
            }
        } else {
            if (element.requestFullscreen) {
                element.requestFullscreen();
            } else if (element.webkitRequestFullScreen) {
                element.webkitRequestFullScreen();
            } else if (element.mozRequestFullScreen) {
                element.mozRequestFullScreen();
            } else if (element.msRequestFullscreen) {
                // IE11
                element.msRequestFullscreen();
            }
        }
        this.fullscreen = !this.fullscreen;
    },

}
export default buttonMethods
